﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukous.Dao.NHibernate;
using Dukous.Security.Dao;
using Dukous.Security.Domain;
using NHibernate;
using NHibernate.Criterion;

namespace Dukous.Security.Dao.NHibernate
{
    public class SecurityObjectDao : EntityDao<SecurityObject, long>, ISecurityObjectDao
    {
        #region ISecurityObjectDao 成员

        public SecurityObject FindByFullName(string fullName)
        {
            IList<SecurityObject> users = this.HibernateTemplate.ExecuteFind<SecurityObject>(delegate(ISession session)
            {
                ICriteria criteria = session.CreateCriteria(typeof(SecurityObject), "obj");
                criteria.Add(Expression.Eq("obj.FullName", fullName));
                return criteria.SetFetchSize(1).List<SecurityObject>();
            });

            return users.FirstOrDefault();
        }

        #endregion
    }
}
